package com.horse.cloud.framework.general.response;




import com.horse.cloud.framework.general.enums.DateEnums;
import com.horse.cloud.framework.general.enums.ResponseCodeEnums;
import com.horse.cloud.framework.general.utils.DateUtils;
import com.horse.cloud.framework.general.utils.IPAddressUtils;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * @create :Created by intelliJ IDEA 16.1.3
 * @author :bing.Pan 15923508369@163.com
 * @gmdate :2017/1/17 18:58
 * @sidesc :系统接口返回通用包装类
 */

@Data
public class Response<T> implements Serializable {

    private static final long serialVersionUID = 355207958304927788L;


    private static final String SERVER_IP_ADDRESS = IPAddressUtils.serverIPAddrMoreNetWork();


    /**
     * // 执行结果状态码
     */
    private int    code;

    /**
     *执行结果状态子码
     */
    private int    subCode;
    /**
     *执行结果消息摘要
     */
    private String message;
    /**
     *执行结果详细信息
     */
    private String detailMessage;
    /**
     *业务数据
     */
    private T      data;
    /**
     * 执行主机
     */
    private String executeHost;

    private String timestamp = DateUtils.date2String(new Date(), DateEnums.HYPHEN_YYYYMMddHHmmssSSS.getPatterns());

    public Response() {
        this.code           = ResponseCodeEnums.SUCCESS.getCode();
        this.subCode        = ResponseCodeEnums.SUCCESS.getSubCode();
        this.message        = ResponseCodeEnums.SUCCESS.getDescription();
        this.detailMessage  = ResponseCodeEnums.SUCCESS.getDetailMessage();
        this.executeHost    = SERVER_IP_ADDRESS;
    }

    public Response(ResponseCodeEnums response) {
        this.code           = response.getCode();
        this.subCode        = response.getSubCode();
        this.message        = response.getDescription();
        this.detailMessage  = response.getDetailMessage();
        this.executeHost    = SERVER_IP_ADDRESS;
    }


    public Response(ResponseCodeEnums response, String detailMessage) {
        this.code           = response.getCode();
        this.subCode        = response.getSubCode();
        this.message        = response.getDescription();
        this.detailMessage  = detailMessage;
        this.executeHost    = SERVER_IP_ADDRESS;
    }


    public Response(int code, String message) {
        this.code           = code;
        this.message        = message;
        this.executeHost    = SERVER_IP_ADDRESS;
    }

    public Response(int code, String message, String detailMessage) {
        this.code           = code;
        this.message        = message;
        this.detailMessage  = detailMessage;
        this.executeHost    = SERVER_IP_ADDRESS;
    }



    public Response(T data) {
        this.code           = ResponseCodeEnums.SUCCESS.getCode();
        this.subCode        = ResponseCodeEnums.SUCCESS.getSubCode();
        this.message        = ResponseCodeEnums.SUCCESS.getDescription();
        this.detailMessage  = ResponseCodeEnums.SUCCESS.getDetailMessage();
        this.data           = data;
        this.executeHost    = SERVER_IP_ADDRESS;
    }


    public static String getServerIpAddress() {
        return SERVER_IP_ADDRESS;
    }





}
